/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.portalnahouby.implementation.serviceimplementation;

import cz.muni.fi.pa165.portalnahouby.api.dto.PickerDTO;
import cz.muni.fi.pa165.portalnahouby.api.serviceinterface.PickerService;
import cz.muni.fi.pa165.portalnahouby.implementation.daointerface.PickerDAO;
import cz.muni.fi.pa165.portalnahouby.implementation.entity.Picker;
import cz.muni.fi.pa165.portalnahouby.implementation.util.EntityDTOConvertor;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Implementation of picker service
 * 
 * @author Lukas Marica
 */
@Service
public class PickerServiceImpl implements PickerService {

	@Autowired
	private PickerDAO pickerDAO;
        
	public void setPickerDAO(PickerDAO pickerDAO) {
		this.pickerDAO = pickerDAO;
	}
	
	@Override
	public void addPicker(PickerDTO picker) {
		Picker pickerEntity = EntityDTOConvertor.convertPicker( picker );
		pickerDAO.addPicker( pickerEntity);
		picker.setId(pickerEntity.getId());
	}

	@Override
	public void editPicker(PickerDTO picker) {
		pickerDAO.editPicker(EntityDTOConvertor.convertPicker( picker ));
	}

	@Override
	public void deletePicker(Long id) {
		pickerDAO.deletePicker(id);
	}

	@Override
	public PickerDTO findPicker(Long id) {
		return EntityDTOConvertor.convertPicker( pickerDAO.findPicker(id) );
	}
	
	@Override
	public PickerDTO findPickerByLoginPass( String name, String pass ) {
		return EntityDTOConvertor.convertPicker( pickerDAO.findPickerByLoginPass(name, pass) );
	}
	

	@Override
	public List<PickerDTO> getAllPickers() {
		List<Picker> entityList = pickerDAO.getAllPickers();
		List<PickerDTO> dtoList = new ArrayList<PickerDTO>();
		for( Picker picker : entityList )
		{
			dtoList.add( EntityDTOConvertor.convertPicker(picker) );
		}
		
		return dtoList;
	}
	
}
